<ul class="dropdown-menu" role="menu">
  <% if agent.can_be_scheduled? %>
    <li>
      <%= link_to icon_tag('glyphicon-refresh', class: 'color-success') + ' 运行', run_agent_path(agent, return: return_to), method: :post, tabindex: "-1" %>
    </li>
  <% end %>

  <% if agent.can_dry_run? %>
    <li>
      <%= link_to icon_tag('glyphicon-refresh') + ' 试运行', '#', 'data-action-url' => agent_dry_runs_path(agent), 'data-with-event-mode' => agent_dry_run_with_event_mode(agent), tabindex: "-1", onclick: "Utils.handleDryRunButton(this)" %>
    </li>
  <% end %>

  <li>
    <%= link_to icon_tag('glyphicon-eye-open') + ' 展示'.html_safe, agent_path(agent, return: return_to) %>
  </li>

  <li class="divider"></li>

  <li>
    <%= link_to icon_tag('glyphicon-pencil') + ' 编辑代理'.html_safe, edit_agent_path(agent, return: return_to) %>
  </li>

  <li>
    <%= link_to icon_tag('fa-copy') + ' 克隆代理'.html_safe, new_agent_path(id: agent), tabindex: "-1" %>
  </li>

  <li>
    <%= link_to '#', 'data-toggle' => 'modal', 'data-target' => "#confirm-agent#{agent.id}" do %>
      <% if agent.disabled? %>
        <%= icon_tag('glyphicon-play') %> 启用代理
      <% else %>
        <%= icon_tag('glyphicon-pause') %> 禁用代理
      <% end %>
    <% end %>
  </li>

  <% if agent.scenarios.length > 0 %>
    <li class="divider"></li>

    <% agent.scenarios.each do |scenario| %>
      <li>
        <%= link_to icon_tag('glyphicon-remove-circle', class: 'color-warning') + " 移除出 #{scenario_label(scenario)}".html_safe, leave_scenario_agent_path(agent, scenario_id: scenario.to_param, return: return_to), method: :put, tabindex: "-1" %>
      </li>
    <% end %>
  <% end %>

  <li class="divider"></li>

  <% if agent.can_create_events? && agent.events_count > 0 %>
    <li>
      <%= link_to icon_tag('glyphicon-trash', class: 'color-danger') + ' 删除所有事件', remove_events_agent_path(agent, return: return_to), method: :delete, data: {confirm: 'Are you sure you want to delete ALL emitted events for this Agent?'}, tabindex: "-1" %>
    </li>
  <% end %>

  <li>
    <%= link_to icon_tag('glyphicon-remove', class: 'color-danger') + ' 删除代理', agent_path(agent, return: return_to), method: :delete, data: { confirm: 'Are you sure that you want to permanently delete this Agent?' }, tabindex: "-1" %>
  </li>
</ul>

<div id="confirm-agent<%= agent.id %>" class="confirm-agent modal fade" tabindex="-1" role="dialog" aria-labelledby="confirmAgentLabel" aria-hidden="true">
  <div class="modal-dialog modal-sm">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">关闭</span></button>
        <h4 class="modal-title">确认</h4>
      </div>
      <div class="modal-body">
        <p><% if agent.disabled? %>启用<% else %>禁用<% end %> &quot;<%= agent.name %>&quot;?</p>
      </div>
      <div class="modal-footer">
        <%= form_for(agent, as: :agent, url: agent_path(agent, return: return_to), method: 'PUT') do |f| %>
          <% if agent.disabled && agent.can_receive_events? %>
            <div class="form-group">
              <%= f.check_box :drop_pending_events %>
              <%= f.label :drop_pending_events, 'Drop pending events' %>
              <span class="glyphicon glyphicon-question-sign hover-help" data-content="As soon as you enable this agent, it starts to receive pending events that have not been processed while it was disabled.  To prevent that from happening, you can check this option."></span>
            </div>
          <% end %>
          <%= f.hidden_field :disabled, value: (!agent.disabled).to_s %>
          <%= f.button 'No', class: 'btn btn-default', 'data-dismiss' => 'modal' %>
          <%= f.submit 'Yes', class: 'btn btn-primary' %>
        <% end %>
      </div>
    </div>
  </div>
</div>

